/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Form1.java
 *
 * Created on Mar 11, 2011, 2:53:29 PM
 */

package vn.support.ui.frame;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import javax.swing.JPopupMenu;
import javax.swing.JSeparator;


import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/**
 *
 * @author ADMIN
 */
public class FormContact extends javax.swing.JFrame {

    /** Creates new form Form1 */
    public FormContact() {
        initComponents();
        loadTree();
        loadTable();
        tblOnline.addMouseListener(new PopClickListener());

    }
        public void loadTree(){
        DefaultMutableTreeNode root= new DefaultMutableTreeNode("Curren Status");
        DefaultMutableTreeNode staffMember= new DefaultMutableTreeNode("Staff Member");
        DefaultMutableTreeNode nguyenTheTuyen= new DefaultMutableTreeNode("Nguyen The Tuyen");
        DefaultMutableTreeNode tuyenNT= new DefaultMutableTreeNode("TuyenNT");
        DefaultMutableTreeNode pendingChats= new DefaultMutableTreeNode("Pending Chats");
        DefaultMutableTreeNode nguyenTT= new DefaultMutableTreeNode("Nguyen The Tuyen");
        DefaultMutableTreeNode transferredChats= new DefaultMutableTreeNode("TransferredChats");

        DefaultTreeModel dtm= new DefaultTreeModel(root);
        dtm.insertNodeInto(staffMember, root, 0);
        staffMember.add(nguyenTheTuyen);
        staffMember.add(tuyenNT);

        dtm.insertNodeInto(pendingChats, root, 1);
        pendingChats.add(nguyenTT);


//        dtm.insertNodeInto(transferredChats, root, 2);
        TreeListContact.setModel(dtm);

    }
     public void loadTable(){

        Vector row= new Vector();
        row.addElement("220.231.96.42");
        row.addElement("Browsing");
        row.addElement("");
        row.addElement("");
        row.addElement("00:00:40");
        row.addElement("");
        row.addElement("http://nttuyen.com");
        row.addElement("Viet Nam");

        DefaultTableModel dtm=(DefaultTableModel)tblOnline.getModel();
        dtm.addRow(row);

     }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PanelStatus = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        PanelContact = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TreeListContact = new javax.swing.JTree();
        jLabel2 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblOnline = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(176, 203, 246));

        PanelStatus.setBackground(new java.awt.Color(176, 203, 246));
        PanelStatus.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel1.setText("Status:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Online", "Offline", "Invisible" }));

        javax.swing.GroupLayout PanelStatusLayout = new javax.swing.GroupLayout(PanelStatus);
        PanelStatus.setLayout(PanelStatusLayout);
        PanelStatusLayout.setHorizontalGroup(
            PanelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelStatusLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(88, Short.MAX_VALUE))
        );
        PanelStatusLayout.setVerticalGroup(
            PanelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelStatusLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        PanelContact.setBackground(new java.awt.Color(77, 123, 205));
        PanelContact.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jScrollPane1.setViewportView(TreeListContact);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Curren Status");

        javax.swing.GroupLayout PanelContactLayout = new javax.swing.GroupLayout(PanelContact);
        PanelContact.setLayout(PanelContactLayout);
        PanelContactLayout.setHorizontalGroup(
            PanelContactLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelContactLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(34, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
        );
        PanelContactLayout.setVerticalGroup(
            PanelContactLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelContactLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE))
        );

        tblOnline.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Chatter ID", "Status", "Deparment", "Operator", "Total Time", "Wait Time", "Current Page", "Country"
            }
        ));
        jScrollPane2.setViewportView(tblOnline);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 886, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 886, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 586, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE))
        );

        jMenuBar1.setBackground(new java.awt.Color(176, 203, 246));

        jMenu1.setText("File");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK));
        jMenuItem1.setText("Exit");
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Help");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(PanelContact, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(PanelStatus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(PanelStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PanelContact, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1213)/2, (screenSize.height-645)/2, 1213, 645);
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new FormContact().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PanelContact;
    private javax.swing.JPanel PanelStatus;
    private javax.swing.JTree TreeListContact;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tblOnline;
    // End of variables declaration//GEN-END:variables

}

class PopUpDemo extends JPopupMenu {
    JMenuItem item4,item5,item6, item7, item9, item11,item12,item13;
    JSeparator item3, item8, item10;
    JMenu item1,item2;

    public PopUpDemo(){
        item1 = new JMenu("Proactive Chat");
        item2 = new JMenu("Open");
        item3 = new JSeparator();
        item4 = new JMenuItem("View Information");
        item5 = new JMenuItem("View Footprints");
        item6 = new JMenuItem("View Note");
        item7 = new JMenuItem("View Historyt");
        item8 = new JSeparator();
        item9 = new JMenuItem("Add Note");
        item10 = new JSeparator();
        item11 = new JMenuItem("Ban");
        item12= new JMenuItem("Request Chat");
        item13= new JMenuItem("Force Chat");
        item1.add(item12);
        item1.add(item13);
        add(item1);
        add(item2);
        add(item3);
        add(item4);
        add(item5);
        add(item6);
        add(item7);
        add(item8);
        add(item9);
        add(item10);
        add(item11);
        

    }
}
class PopClickListener extends MouseAdapter {
    public void mousePressed(MouseEvent e){
        if (e.isPopupTrigger())
            doPop(e);
    }
    public void mouseReleased(MouseEvent e){
        if (e.isPopupTrigger())
            doPop(e);
    }
    private void doPop(MouseEvent e){
        PopUpDemo menu = new PopUpDemo();
        menu.show(e.getComponent(), e.getX(), e.getY());
    }
}